﻿using Lg.Core.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lg.Core.Form.Types
{
    public class Switch : BaseType, IType
    {
        public List<Option>? Options { get; set; }
        public string? OtherTitle { get; set; }
        public string? OtherTips { get; set; }
        public string? OtherName { get; set; }
        public string? OtherValue { get; set; }
        public string? OtherRows { get; set; }
        public string? OtherTextRange { get; set; }
        public void Verify()
        {

        }
        public void GetSaveDbValue(Dictionary<string, dynamic> formData, string inputValue)
        {
            if (string.IsNullOrEmpty(inputValue))
            {
                formData.Add(Name, "");
                return;
            }
            else
            {
                var op = Options?.FirstOrDefault(o => o.Text == inputValue);
                if (op != null)
                {
                    formData.Add(Name, new { opid = op.Id, value = inputValue });
                    return;
                }
                else
                {
                    formData.Add(Name, new { opid = 0, value = inputValue });
                    return;
                }
            }

        }
    }

}
